13
Notation of ADT
An example
wAs an example the description of the ADT Integer is presented. Let k be an integer expression:
wADT Integer is
w Data
w A sequence of digits optionally prefixed by a plus or minus sign. We refer to this signed whole number as N.
w Operations
w constructor: Creates a new integer.
w add(k): Creates a new integer which is the sum of N and k. The postcondition for this operation is su b= N+k.
w sub(k): Similar to add, this operation creates a new integer of the difference of both integer values. => the postcondition for this operation is sum = N-k.
w set(k): Set N to k. The postcondition for this operation is N = k.
wend
The description above is a specification for the ADT Integer. Please notice, that we use words for names of operations such as ``add''. We could use the more intuitive ``+'' sign instead, but this may lead to some confusion: You must distinguish the operation ``+'' from the mathematical use of ``+'' in the postcondition. The name of the operation is just syntax whereas the semantics is described by the associated pre- and postconditions. However, it is always a good idea to combine both to make reading of ADT specifications easier.
Real programming languages are free to choose an arbitrary implementation for an ADT. For example, they might implement the operation add with the infix operator ``+'' leading to a more intuitive look for addition of integers.